package net.lainiao.morethread.Chapter4.demo5;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/3.
 */
public class Task implements Callable<Result> {
    private String name;
    public Task(String name){
        this.name=name;
    }
    @Override
    public Result call() throws Exception {
        System.out.println(this.name+" Starting");
        long duration=(long)(Math.random()*10);
        System.out.println(this.name+" waiting "+duration+" seconds for results");
        TimeUnit.SECONDS.sleep(duration);
        Result result=new Result();
        result.setName(this.name);
        int value=0;
        for (int i = 0; i < 5; i++) {
            value+=(int)(Math.random()*100);
        }
        result.setValue(value);
        System.out.println(this.name+" Ends");
        return result;
    }



}
